package com.jilefojing.beans.enums;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * 第三方类型
 * 
 * @author jgshun
 * 
 */
public enum ThirdPartyTypeEnum {
	/**
	 * (short) 1, "QQ"
	 */
	QQ((short) 1, "QQ"),
	/**
	 * (short) 2, "新浪"
	 */
	XIN_LANG((short) 2, "新浪"),
	/**
	 * (short) 0, "未知"
	 */
	UNKNOWN((short) 0, "未知");
	;

	// (1-QQ 2-新浪)
	private short value;
	private String msg;

	private ThirdPartyTypeEnum(short value, String msg) {
		this.value = value;
		this.msg = msg;
	}

	public short getValue() {
		return value;
	}

	public void setValue(short value) {
		this.value = value;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public static ThirdPartyTypeEnum getThirdPartyTypeEnumByValue(short value) {
		for (ThirdPartyTypeEnum thirdPartyTypeEnum : ThirdPartyTypeEnum.values()) {
			if (value == thirdPartyTypeEnum.value) {
				return thirdPartyTypeEnum;
			}
		}
		return ThirdPartyTypeEnum.UNKNOWN;
	}

	@Override
	public String toString() {
		if (this != null) {
			Map<String, Object> allMap = new HashMap<String, Object>();
			allMap.put("value", this.value);
			allMap.put("msg", this.msg);

			String result = JSONObject.toJSONString(allMap);
			result = result.replaceAll("\"", "'");
			return result;
		}
		return super.toString();
	}

}
